package com.foreknow.controller;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet(name = "ServletDemo",urlPatterns = {"/demo"},initParams = {
        @WebInitParam(name="abc",value="123"),
        @WebInitParam(name="def",value="456")

})
public class ServletDemo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("可以使用注解的方式来创建一个servlet"+"<br>");
        out.println(new Date());
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        String abc = config.getInitParameter("abc");
        String def = config.getInitParameter("def");
        System.out.println(abc);
        System.out.println(def);
    }
}
